﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Home.MobileSales.Common.Models;

namespace Home.MobileSales.ImpExpData.Core
{
    public class ExportNewVisits : ExportVisits
    {
        public override void Execute()
        {
            try
            {
                visits = DataManager.GetInstance().Visists.GetAllVisitsForExport();
                xml = XmlWriter.Create(FileName.FullName);
                xml.WriteStartDocument();
                xml.WriteStartElement("Visits");
                //xml.WriteStartAttribute("Params");
                //xml.WriteValue("only new Visit");
                //xml.WriteEndAttribute();
                ExportVisit();
                xml.WriteEndElement();
                xml.WriteEndDocument();
                foreach (var visit in visits)
                {
                    visit.IsReadOnly = true;
                    DataManager.GetInstance().Visists.UpdateVisit(visit);
                    foreach (var order in visit.Orders)
                    {
                        order.IsReadOnly = true;
                        DataManager.GetInstance().Orders.UpdateOrder(order);
                    }
                }
            }
            finally
            {
                if (xml != null)
                {
                    xml.Close();
                }
            }

        }
    }
}
